public class Student3 {

    String name;
    String teacher;
    String date;//开班时间
    //    int sum;//统计全班人数；
    String[] a = new String[20];
    public void add(String stuname) {
        for (int i = 0; i < a.length; i++) {
            if (stuname.equals(a[i])) {
                System.out.println("姓名已有，添加失败");
                break;
            }
            if (a[i] == null) {
                a[i] = stuname;
                break;
            }
        }
    }

    public void show() {
        System.out.println("学生信息");
        for (int i = 0; i < a.length; i++) {
            if (a[i] == null)
                break;
            System.out.print(a[i] + " ");
        }
    }

    public boolean searchName(String name) {
        for (int i = 0; i < a.length; i++) {
            if (a[i] == null)
                return false;
            if (name.equals(a[i]))
                return true;
        }
        return false;
    }

    public String find(int index) {
        if (a[index] == null)
            return "查无此人";
        return a[index];
    }

    public boolean update(String oldName, String newName) {
        for (int i = 0; i < a.length; i++) {
            if (oldName.equals(a[i])) {
                a[i] = newName;
                break;
            }
            if (a[i] == null) {
                a[i] = newName;
                break;
            }
        }
        return false;
    }

    public int getNum() {
        int i = 0;
        for (; i < a.length; i++) {
            if (a[i] == null)
                break;
        }
        return i;
    }
}


